package com.xuzao.developer.dao.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xuzao.developer.base.criteria.GridTableCriteria;
import com.xuzao.developer.base.model.GridTable;
import com.xuzao.developer.dao.GridTableDao;
import com.xuzao.developer.dto.GridTableDTO;
import com.xuzao.developer.mapper.GridTableMapper;
import com.xuzao.developer.tools.base.BaseServiceSupport;
import com.xuzao.developer.tools.entity.Pager;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


/**
 * @author xuzao
 * @description
 * @date 2019-09-03 17:12:36
 **/
@Service("gridTableDao")
public class GridTableDaoImpl extends BaseServiceSupport<GridTable> implements GridTableDao {

    @Resource
    private GridTableMapper gridTableMapper;


    @Override
    public PageInfo<GridTable> list(GridTableDTO dto, Pager pager) {
        GridTableCriteria criteria = this.assemblyQuerycond(dto);
        if (null != pager) {
            if (null != pager.getPageCurrent() && null != pager.getNumPerPage()) {
                PageHelper.startPage(pager.getPageCurrent(), pager.getNumPerPage());
            }
        }
        PageInfo<GridTable> pageInfo = new PageInfo<>(this.gridTableMapper.selectByExample(criteria));
        return pageInfo;
    }

    //通用查询方法条件组装
    public GridTableCriteria assemblyQuerycond(GridTableDTO dto) {
        GridTableCriteria criteria = new GridTableCriteria();
        GridTableCriteria.Criteria c = criteria.createCriteria();

        if (null != dto) {
            if (StringUtils.isNotBlank(dto.getGridName())) {
                c.andGridNameLike("%" + dto.getGridName() + "%");
            }
        }
        c.andIsDeletedEqualTo(0);
        return criteria;
    }
}